<?php
namespace app\admin\controller;
use think\Controller;
use think\Url;
use think\Db;
use think\Request;

class Goods extends Controller
{
    public function index()
    {
        // 设置模板内容
        $this->assign('title', 'Showing - 后台商品管理');
        // 加载模板(view)
        return $this->fetch('admin/goods');
    }

    public function create()
    {
        $data = Db::name('goods_category')->field(['id', 'category_name', 'pid', 'level'])->select();
        $data = goodstree($data);
        // var_dump($data);exit;

        $this->assign([
            'title'=>'Showing - 后台商品添加',
            'data'=>$data,

        ]);

        return $this->fetch('admin/goods_create');
    }

    public function save(Request $request)
    {
        $data = input('post.');
        $file = $request->file('goods_img');
        $info = $file->validate(['size'=>51200, 'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
        if ($info){
            echo $info->getFilename();
        } else {
            echo $file->getError();
        }
        // var_dump($info);

    }
}